# -*- coding: utf-8 -*-

'''eof
name:当前订单金额
code:EB02_OrderAmount
tableName:
columnName:
groups:中标信息模块
dependencies:EG_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import re
import datetime
import  json
import numpy as np
reload(sys)
sys.setdefaultencoding('utf-8')

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']

def isfloat(x):
    '''
    判断x为float类型且大于等于0
    :param x:
    :return:
    '''
    try:
        if isinstance(float(x), float) and float(x)>=0:
            if str(x) in ['inf', 'infinity', 'INF', 'INFINITY', 'True']:
                return False
            else:
                return True
        else:
            return False
    except:
        return False
def EB02_OrderAmount():
    try:
        #政采中标信息
        #governmentProcurementInfo=ratingRequest.get("governmentProcurementInfo")
        governmentProcurementInfo = json.loads(ratingRequest.get("governmentProcurementInfo"))
        #供应商合同集合
        contractList=governmentProcurementInfo.get("contractList")

        isSelect=["1",1]
        amount=[]
        result_list = []
        if governmentProcurementInfo in null_type_list or contractList in null_type_list :
            return u'缺失值'
        else:
            for i in contractList:
                if i.get("isSelect") in null_type_list  or \
                        i.get("totalAmount") in null_type_list   or isfloat( i.get("totalAmount"))==False \
                        or  i.get("createTime") in null_type_list\
                        or (i.get("createTime")+str(i.get("totalAmount") )) in result_list:
                    amount.append(0)
                    continue
                elif i.get("isSelect") in isSelect  :
                    amount.append(float(i.get("totalAmount")))
                    result_list.append (i.get("createTime")+str(i.get("totalAmount")) )
                else:
                    amount.append(0)

        return np.sum(amount)
    except:
        return u'缺失值'

if __name__ == '__main__':
    file_obj = open(r'E:\\changjiang_bd\\EBjson20190926.json', 'r')
    content = file_obj.read()
    ratingRequest = json.loads(content)
    print EB02_OrderAmount()


result = EB02_OrderAmount()

